package com.shuoyue.ycgk.views.dialog.speeddialog;

import android.graphics.drawable.Drawable;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;

import java.util.List;

/**
 * 倍速适配器
 */
public class SpeedAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    String selected = "1X";

    public SpeedAdapter(List data) {
        super(R.layout.item_speed, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, String item) {
        helper.addOnClickListener(R.id.lay_all);
        helper.setText(R.id.tv_title, item);
        setDrawable(helper.getView(R.id.tv_title), selected.equals(item));
    }

    public void setSelected(String selected) {
        this.selected = selected;
    }


    /**
     * 设置热点新闻的hot图标
     *
     * @param view
     */
    private void setDrawable(TextView view, boolean isShow) {
        Drawable drawable = ContextCompat.getDrawable(mContext,
                R.mipmap.icon_speed_select);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(),
                drawable.getMinimumHeight());
        view.setCompoundDrawables(null, null, isShow ? drawable : null, null);
    }
}